﻿Imports UnScripter.Project

' Singleton for dealing with Projects
Class ProjectManager
    Shared ReadOnly Property ProjectOpen As Boolean
        Get
            Return Not IsNothing(Globals.CurrentProject)
        End Get
    End Property

    Public Shared Sub ChangeProject(ByRef newproject As Project.Project)
        ' Clear all the old files from the fileview
        MainForm.FileView.Nodes.Clear()

        ' Are we using a tree format or a straight list
        If Globals.kUseFileTree Then
            newproject.FileTreeView = New ProjectFileTree(newproject.ProjectName, MainForm.FileView, newproject.DevelopmentFolder, Globals.kProjectFileRegex)
        Else
            Dim paren = MainForm.FileView.Nodes.Add(newproject.ProjectName)
            For Each actfilename In newproject.FileList.RelativeFiles
                paren.Nodes.Add(actfilename)
            Next
        End If

        Globals.Settings.SetTrait("LastProjectPath", newproject.ProjectFileName)
        MainForm.FileStatusLabel.Text = "Opened Project " & newproject.ProjectName

        MainForm.StartParser()

        newproject.FileTreeView.ExpandDefaultFolders()
    End Sub

    Public Shared Function CreateProject(ByRef name As String, ByRef path As String) As Project.Project
        Dim newproject As New Project.Project(name, path, Globals.kProjectFileRegex)
        Return newproject
    End Function

    Public Shared Function OpenProject(ByRef path As String) As Project.Project
        Return Project.Project.OpenProject(path)
    End Function

End Class